package main;

import com.alibaba.druid.sql.visitor.SQLASTOutputVisitor;
import entity.Book;
import org.junit.Test;
import service.BookService;
import service.impl.BookServiceImpl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/*
杨威
2021/9/7
21:49
*/
public class TestBook {
    BookService bookService=new BookServiceImpl();
    @Test
    public void selectByDate(){
        List<Book> books = bookService.selectAllOrderByDateBook();
        books.forEach(System.out::println);
    }
    @Test
    public void TestSelectCount(){
        long l = bookService.selectCountBook();
        System.out.println("l = " + l);
    }
    @Test
    public void TestInsertBook(){
        try {
            Date parse = new SimpleDateFormat("yyyy-mm-dd").parse("1562-2-3");
            Book book=new Book(0,"mybatis","wei",parse,"海天出版社","15415616",500.3);
            int i = bookService.addBook(book);
            System.out.println("i = " + i);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
    @Test
    public void TestBookById(){
        Book book = bookService.selectById(5);
        System.out.println("book = " + book);
    }
    @Test
    public void TestSelectAllBook(){
        List<Book> books = bookService.selectAllBook();
        books.forEach(System.out::println);
    }
    @Test
    public void TestDeleteBookById(){
        int i = bookService.deleteBook(10);
        System.out.println("i = " + i);
    }
    @Test
    public void TestUpdateBookTitle(){
        Book book=new Book();
        book.setbId(9);
        book.setbTitle("勇敢的心");
        int i = bookService.updateBook(book);
        System.out.println("i = " + i);
    }
}
